#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
#include <math.h>  

int func(int* a, int from, int to, char b[], int M)
{

	if (from > to)   return M;
	int k, t;
	k = func(a, from + 1, to, b, M - a[from]);
	t = func(a, from + 1, to, b, M);
	if (fabs(k) < fabs(t))
	{
		b[from] = 't';
		return func(a, from + 1, to, b, M - a[from]);
	}
	else
	{
		b[from] = 'f';
		return func(a, from + 1, to, b, M);
	}

}
int main()
{
	int t[21];
	int n, M, N = 0;
	int sum = 0;
	int a;
	char* b;
	scanf("%d", &n);
	b = (char*)malloc(sizeof(char) * n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &t[i]);
		sum = sum + t[i];
	}
	M = sum / 2;
	func(t, 0, n - 1, b, M) + M;

	for (int i = 0; i < n; i++)
	{
		if (b[i] == 't')
		{
			N = N + t[i];
		}
	}
	if (sum - N > N) a = sum - N - N;
	else a = N - sum + N;
	printf("%d\n", a);
	return 0;
}